package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.TestConstant;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.adapter.ADGoodsSizeTag;
import com.zlzxm.shoesmarket.view.adapter.entity.EntitySizeMoveDetail;
import com.zlzxm.shoesmarket.view.window.wheelpick.EntityOption;
import com.zlzxm.shoesmarket.viewmodel.entity.EntityTransfer;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * CREATE BY zlzxm ON 4/20/21
 */
public class VMSizeMove extends ViewModel {

    private MutableLiveData<EntityTransfer> liveGoodsInfo = new MutableLiveData<>();

    private MutableLiveData<List<EntitySizeMoveDetail>> liveSizeDetail = new MutableLiveData<>();

    private final MutableLiveData<List<EntityOption>> liveRepository = new MutableLiveData<>();

    public MutableLiveData<List<EntityOption>> getLiveRepository() {
        return liveRepository;
    }

    public MutableLiveData<EntityTransfer> getLiveGoodsInfo() {
        return liveGoodsInfo;
    }

    public MutableLiveData<List<EntitySizeMoveDetail>> getLiveSizeDetail() {
        return liveSizeDetail;
    }

    public void requestInfo(){

        Observable.timer(3, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {


                    }
                });





    }


    public void requestSize(){

        Observable.timer(3, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                        liveSizeDetail.setValue(createTestData2());

                    }
                });



    }


    public void requestRepository(){

        Observable.timer(1,TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });



    }


    //<editor-fold defaultState="collapsed" desc="测试">



    private List<EntitySizeMoveDetail> createTestData2(){


        List<EntitySizeMoveDetail> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {

            EntitySizeMoveDetail entitySizeMoveDetail= new EntitySizeMoveDetail();
            entitySizeMoveDetail.setNum("32");
            entitySizeMoveDetail.setSize("45");


            list.add(entitySizeMoveDetail);


        }

        return list;

    }


    private List<EntityOption> createRepositoryList(){

        List<EntityOption> list = new ArrayList<>();

        for (int i = 0; i < 50; i++) {

            list.add(new EntityOption(0+"","仓库"+i));
        }

        return  list;
    }


    // </editor-fold>
}
